 <template>
    <div class="m-auth-wrapper">
        <img :src="loadingPic" alt="">
    </div>
</template>

<script>
import store from "../store/store";
import { mapState } from "vuex";
export default {
  name: "Author",
  store,
  data() {
    return {
      webUrl: "",
      loadingPic: require("../assets/images/loading1.gif")
    };
  },
  created() {
    let token = this.$route.query.token;
    let user = this.$route.query.user;
    if (token && user) {
      window.localStorage.setItem("token", token);
      window.localStorage.setItem("user", user);
      this.$store.dispatch("setUserInfo", JSON.parse(JSON.stringify(user)));
      setTimeout(() => {
        this.goBeforeLoginUrl(); // 页面恢复(进入用户一开始请求的页面)
      }, 2000);
    } else {
      window.location.href = "http://api.rjveg.pw/api/user/profile";
    }

    // if (!window.localStorage.getItem("token")) {
    //     let ua = window.navigator.userAgent.toLowerCase();
    //     if (ua.match(/MicroMessenger/i) == 'micromessenger') {
    //         window.location.href = 'http://www.ittie.cn/api/user/profile';
    //     }
    // } else {
    // }
    // if (!window.localStorage.getItem('user')) {
    //     let ua = window.navigator.userAgent.toLowerCase()
    //     if (ua.match(/MicroMessenger/i) == 'micromessenger') {
    //         window.location.href = 'http://www.ittie.cn/api/user/profile';
    //     }
    // } else {
    // 如果有token 但是vuex中没有用户登录信息则做登录操作
    // this.login()
    // }
  },
  mounted() {},
  methods: {
    // login() {
    //     let url = this.webUrl + '/Wap/User/info'
    //     this.$http.get(url).then(response => {
    //         response = response.body
    //         if (response) {
    //             // 保存用户登录状态(Vuex)
    //             this.$store.commit('user', response)
    //             setTimeout(() => {
    //                 this.goBeforeLoginUrl() // 页面恢复(进入用户一开始请求的页面)
    //             }, 2000)
    //         } else {
    //             if (util.cookie.get('user')) {
    //                 // 跳转到微信授权页面
    //                 window.location.href = 'http://ittie.cn/api/user/profile';
    //                  window.location.href = this.webUrl + '/Wap/User/getOpenid'
    //             }
    //         }
    //     })
    // },
    getUrlParams(name) {
      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
      var r = window.location.href.match(reg);
      if (r != null) return unescape(r[2]);
      return null;
    }
  }
};

function GetQueryString(name) {
  let reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)", "i");
  if (reg.test(window.location.href)) {
    return unescape(RegExp.$2.replace(/\+/g, " "));
  }
  return undefined;
}
</script>

<style scoped>
.m-auth-wrapper {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>